"""
@description: Training of the face recognition model.
@author: ZDZ, GHY
@create: 2022/07/13
"""
from imutils import paths
from elderlyCare.facial import FaceUtils

# from util import oss_upload_model, oss_download_image

# global variable
dataset_path = "resources/images"
output_encoding_file_path = 'generate/models/face_recognition_hog.pickle'
output_version_path = 'generate/models/model_version.txt'


def train_face():
    """
    Train the model of face recognition.
    :return: Model trained
    """
    # grab the paths to the input images in our dataset
    print("[INFO] Quantifying faces...")
    image_paths = list(paths.list_images(dataset_path))

    if len(image_paths) == 0:
        print("[ERROR] No images to train...")
        return "error"
    else:
        # oss_download_image()
        face_utils = FaceUtils()
        print("[INFO] training face embeddings...")
        face_utils.save_embeddings(image_paths, output_encoding_file_path)
        # oss_upload_model(output_encoding_file_path, output_version_path)
